package com.xingkeduo.business.operation.service;

import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.HairstyleQuery;
import com.xingkeduo.pojo.table.HairstyleTable;
import com.xingkeduo.util.pojo.domain.Page;
import com.xingkeduo.util.tool.CommonUtil;
import com.xingkeduo.util.tool.IdentityUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件概述
 *
 * @author chenxiangda <chenxiangda@xingkeduo.com>
 * @version id:v0.1 ${date}${time}
 * @package BeautyOS
 * @copyright Copyright (c) XKD 2019
 */
@Component
public class HairstyleService {
    private static final String NAMESPACE = HairstyleTable.class.getSimpleName();

    @Resource(name = "mysqlOperationDao")
    private DatabaseAccessObject<HairstyleTable, HairstyleQuery> dao;

    //查询一条
    public HairstyleTable selectById(long id) throws Throwable {
        HairstyleTable hairstyleTable = dao.select(NAMESPACE, id);
        if (!CommonUtil.isEmpty(hairstyleTable))
            return hairstyleTable;
        return null;
    }

    //查询多条
    public List<HairstyleTable> selectHairstyles(HairstyleQuery hairstyleQuery) throws Throwable {
        hairstyleQuery.setStatus(1);
        List<HairstyleTable> hairstyleTableList = dao.select(NAMESPACE, hairstyleQuery);
        if (!CommonUtil.isEmpty(hairstyleTableList))
            return hairstyleTableList;
        return null;
    }

    //分页查询
    public Page<HairstyleTable> selectPageLists(HairstyleQuery hairstyleQuery, Integer pageNo, Integer pageSize) throws Throwable {
        Page<HairstyleTable> hairstyleTablePage = dao.pageSelect(NAMESPACE,hairstyleQuery,pageNo,pageSize);
        return hairstyleTablePage;
    }


    //插入
    public int insert(HairstyleTable hairstyleTable) throws Throwable {
        Long code = IdentityUtil.nextId(IdentityUtil.Worker.DEFAULT);
        hairstyleTable.setCode(code);
        return dao.insert(NAMESPACE, hairstyleTable);
    }

    //更新
    public int update(HairstyleTable hairstyleTable) throws Throwable {
        return dao.update(NAMESPACE, hairstyleTable);
    }

    public int delete(HairstyleTable hairstyleTable) throws Throwable {
        return dao.update(NAMESPACE, hairstyleTable);
    }

    //批量
    public int updateRows(HairstyleTable hairstyleTable,HairstyleQuery hairstyleQuery) throws Throwable {
        return dao.update(NAMESPACE,hairstyleTable,hairstyleQuery);
    }

}
